package com.ebs.spring.jms;

/**
 * Revision Author:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/spring/jms/JmsTemplateWithAuth.java $
 *  $Revision: #1 $
 *  $DateTime: 2012/05/09 12:02:58 $
 *  $Change: 110898 $
 *  $Author: Arik.Sher $
 */

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.JmsAccessor;
import org.springframework.util.StringUtils;

/**
 * extending Spring's class JmsTemplate, so could support username n password, "createConnection" ability.
 * 
 * @see JmsTemplate
 * @see JmsAccessor
 */
public class JmsTemplateWithAuth 
extends JmsTemplate
{
	protected String mqUsername = null;
	protected String mqPassword = null;
	
	public void setUsername(String mqUsername) {
		this.mqUsername = mqUsername;
	}
	public void setPassword(String mqPassword) {
		this.mqPassword = mqPassword;
	}

	@Override
	protected Connection createConnection() throws JMSException {
		if ( !StringUtils.hasText(mqUsername) ) {
			return super.createConnection();
		}
		ConnectionFactory cf   = getConnectionFactory();
		Connection        conn = cf.createConnection(mqUsername, mqPassword);
		return conn;
	}
	
}
